<template>
  <div class="inform">
    <!-- 按钮 -->
    <div class="btns">
      <el-button class="iconfont icon-icon-test" size="small" type="primary" @click="toAdd" >添加</el-button>
    </div>
    <!-- 表格 -->  
    <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号" > </el-table-column>
      <el-table-column prop="id" label="唯一Id" v-if="false"></el-table-column>
      <el-table-column prop="content" label="文章内容" > </el-table-column>
      <el-table-column prop="articleId" label="文章id" > </el-table-column>
      <el-table-column prop="userId" label="文章发布者id" > </el-table-column>
      <el-table-column label="操作"  width="150px" align="center"> 
        <template v-slot="scope">
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
          <el-button size="small" type="danger" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 模态框 -->
    <el-dialog class="customer_modal" title="添加inform" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">
        {{form}}
      <el-form :model="form" label-width="100px">
        <el-form-item label="内容" >
          <el-input v-model="form.content" ></el-input>
        </el-form-item>
        <el-form-item label="文章id" >
          <el-input v-model="form.articleId" ></el-input>
        </el-form-item>
        <el-form-item label="文章发布者id" >
          <el-input v-model="form.userId" ></el-input>
        </el-form-item>
      </el-form>
       
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="save(form)" size="small">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {get,post} from '@/utils/request'
export default {
  data (){
    return {
      form:{},
      list:[],
      dialogVisible:false
    }
  },
  created(){
      this.loadData();
  },
  methods:{
    save(){
      let url ="/inform/saveOrUpdate";
      post(url,this.form).then( (response)=>{
        //模态框关闭
        this.dialogVisible=false;
        //提示
        this.$message({type:"success",message:response.message});
        //刷新
        this.loadData();
        
      })
    },
    del(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
      let url ="/inform/deleteById";
      get(url,{id:row.id}).then( (response)=>{
         //提示
         this.$message({type:"success",message:response.message})
         //刷新
         this.loadData();
       } )
      })
    },
    edit(row){
        this.form=row;
        this.dialogVisible=true;
    },
    loadData(){
      let url ="/inform/findAll";
      get(url).then((response)=>{
        this.list=response.data;
      });
    },
    toAdd(){
      this.dialogVisible = true;
    }
  }
}
</script>
